package com.faker.service;

import com.faker.dao.ConnectionOperatorDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class ConnectionOperatorService {


    @Resource
    private ConnectionOperatorDao connectionOperatorDao;

    public List<Map<String, Object>> getTableList(Long connectionId) {
        List<Map<String, Object>> result = new ArrayList<>();
        List<Map<String, Object>> tableList = connectionOperatorDao.getTableList();
        for (Map<String, Object> tableMap : tableList) {
            HashMap<String, Object> map = new HashMap<>();
            Object tableName = tableMap.get("tableName").toString();
            map.put("icon", "el-icon-date");
            map.put("connectionId", connectionId);
            map.put("tableName", tableName);
            result.add(map);
        }
        return result;
    }

    public List<Map<String, Object>> getFieldList(String tableName) {
        List<Map<String, Object>> fieldList = connectionOperatorDao.getFieldList(tableName);
        return fieldList;
    }


}
